package demo4;

import java.util.Arrays;

class Student implements Comparable<Student>{
    public int age;
    public String name;
    public double score;

    public Student(int age, String name, double score){
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o){
//        if(this.age > o.age){
//            return 1;
//        }else if(this.age == o.age){
//            return 0;
//        }else{
//            return -1;
//        }
        return this.age - o.age;
    }
}

public class Test {

    public static void main2(String[] args) {
        Student student1 = new Student(12,"bit", 98.8);
        Student student2 = new Student(6,"abc",18.8);
        System.out.println(student1.compareTo(student2));
    }

    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student(12,"bit", 98.8);
        students[1] = new Student(6,"abc",18.8);
        students[2] = new Student(18,"zhangsan", 88.9);
        System.out.println(Arrays.toString(students));
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }

    public static void main1(String[] args) {
        int[] array = {1,21,3,14,5,16};
        System.out.println(Arrays.toString(array));
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
}
